package com.acme.javaschool.sems.ionio.serialization.impl;

import com.acme.javaschool.sems.ionio.serialization.SensorData;
import com.acme.javaschool.sems.ionio.serialization.Serializer;

import java.io.*;

public class JavaSerializer implements Serializer<SensorData> {

    @Override
    public void serialize(OutputStream outputStream, SensorData object) {
        try {
            ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);
            objectOutputStream.writeObject(object);
        } catch (IOException e) { e.printStackTrace(); }
    }

    @Override
    public SensorData deserialize(InputStream inputStream) {
        try {
            ObjectInputStream objectInputStream = new ObjectInputStream(inputStream);
            return (SensorData) objectInputStream.readObject();
        } catch (IOException | ClassNotFoundException e) { e.printStackTrace(); }
        return null;
    }

}
